  <%
      String type = request.getParameter("type");
	  if(type == null){
		   type = "";
	  }
  %>
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/scripts/UploadDialog/upload-dialog.css" />
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/scripts/UploadDialog/css/Ext.ux.UploadDialog.css" />
<script
	src="<%=request.getContextPath()%>/scripts/UploadDialog/Ext.ux.UploadDialog.packed.js"
	language="javascript"></script>
<script language="javascript">

	 function hiddenUpload(req, fileId){
		 return function () {
           if (req.readyState == 4 && req.status == 200) {
                  var x = document.getElementById("res_"+fileId);
				  x.style.display = 'none';
			   }
		 }
	 }

	 function remove_resUpload(fileId){
            var req = AjaxRequest();
			if(req != null){
				var handlerFunction = hiddenUpload(req, fileId);
                req.onreadystatechange = handlerFunction;
                req.open("POST", "<%=request.getContextPath()%>/pages/upload/upload.jsp?actionType=remove&fileId="+fileId, true);
                req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			    req.send("actionType=remove&fileId="+fileId);
			}
	 }

	var UploadDialogController = function() {
	  var dialog = null;  
	  var button = null;
	  var file_list_tpl = new Ext.Template(
		"<div class='file-list-entry'>File {name} successfuly uploaded.</div>"
	  );
	  file_list_tpl.compile();

	  function hideLoadingMask() {
		  Ext.get(document.body).setStyle('overflow', 'visible');
	  }

    function getDialog() {
		if (!dialog) {
			dialog = new Ext.ux.UploadDialog.Dialog({
			url: '<%=request.getContextPath()%>/pages/upload/upload.jsp?actionType=upload&type=<%=type%>',
			reset_on_hide: false,
			allow_close_on_upload: true,
			upload_autostart: false, 
			post_var_name: 'upload'
		  });
		  dialog.on('uploadsuccess', onUploadSuccess);
		}
		return dialog;
	  }
  
   function showDialog(button) {
        getDialog().show(button.getEl());
   }
  
  function onUploadSuccess(dialog, filename, resp_data, record) {
    var parts = filename.split(/\/|\\/);
    if (parts.length == 1) {
      filename = parts[0];
    }
    else {
      filename = parts.pop();
    }
  }

  return {
    init : function() {
      Ext.QuickTips.init();
      button = new Ext.Button({
        renderTo: 'x-show-dialog-btn',
        id: 'x-show-button',
        text: '<%=com.gzgi.framework.config.MessageProperties.getString("res_upload")%>',
        handler: showDialog
      });
      hideLoadingMask();
      Ext.get(document.body).setStyle('overflow', 'auto');
    }
  }
}();

</script>